//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/ienum/home/column_type_enum.dart';
import 'package:hktk_app/ienum/practice/ct_enum.dart';
import 'package:hktk_app/ienum/practice/one_do_source_enum.dart';
import 'package:hktk_app/ienum/question/first_type_enum.dart';
import 'package:hktk_app/model/subject/note_model.dart';
import 'package:hktk_app/pages/question/single_question_page.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/my_util.dart';

import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/question/stem_rich_text_widget.dart';

class NoteShowWidget extends StatelessWidget {
  /// 笔记相关数据
  final NoteModel noteModel;

  /// 相关类型
  final ColumnTypeEnum columnType;

  const NoteShowWidget({
    super.key,
    required this.noteModel,
    required this.columnType,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: columnType == ColumnTypeEnum.zx
          ? EdgeInsets.all(15)
          : EdgeInsets.zero,
      padding: columnType == ColumnTypeEnum.zx
          ? EdgeInsets.all(20)
          : EdgeInsets.only(bottom: 20, left: 20, right: 20),
      decoration: BoxDecoration(
        color: colorWhite1, borderRadius: BorderRadius.circular(20),
        // border: Border(bottom: BorderSide(color: colorGrey3, width: 1)),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _topItem(context),
          hiSpace(height: 10),
          _bottomItem(),
        ],
      ),
    );
  }

  /// 顶部组件显示
  _topItem(BuildContext context) {
    return Row(
      children: [
        Expanded(
          child: Text(
            noteModel.content!,
            style: FontUtil.fontBlack1(22),
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
        ),
        hiSpace(width: 10),
        _btnItem(context),
      ],
    );
  }

  /// 按钮组件显示
  _btnItem(BuildContext context) {
    return GestureDetector(
      onTap: () {
        _onTapFunCk(context);
      },
      child: Container(
        // width: 100,
        // height: 40,
        decoration: BoxDecoration(
          color: colorBlue1,
          borderRadius: BorderRadius.circular(30),
        ),
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 20, vertical: 3),

          child: Text(
            "查看",
            style: FontUtil.fontWhile1(18, fontWeight: FontWeight.w400),
          ),
        ),
      ),
    );
  }

  /// 查看按钮点击
  void _onTapFunCk(BuildContext context) {
    Navigator.pushNamed(context, "/single-question",arguments: {
      "collectId": noteModel.relationId!,
      "paperName": "我的笔记",
      "qId": noteModel.questionId!,
      "qType": FirstTypeEnum.singleChoice,
      "rType": CtEnum.chapter,
      "view": false,
      "oneDoSourceEnum": OneDoSourceEnum.note,
    });
  }

  /// 底部显示
  _bottomItem() {
    return StemRichTextWidget(
      text: _getStemStr(),
      textStyle: TextStyle(
        fontSize: 20,
        fontWeight: FontWeight.w400,
        color: colorBlack1,
      ),
    );
  }

  String _getStemStr() {
    String tg = MyUtil.getStemStr(noteModel.stem);
    String str = "<p>来源：";
    int index = tg.indexOf("<p>");
    if (index != -1) {
      tg = tg.substring(index + 3);
    }
    return str + tg;
  }
}
